package com.freen.fadmin.entity.sysuser;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.Data;

import javax.persistence.*;
import java.util.List;


@Entity
@Table(name = "sys_role",schema = "sys_role")
//@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,property = "id")
@JsonIgnoreProperties(value = { "userInfos" })
public class SysRole {
    @Id
    @GeneratedValue
    private Integer id;
    @Column(name = "cnname",length = 20,nullable = false,unique = true)
    private String cnname;
    @Column(name = "role",length = 20,nullable = false,unique = true)
    private String role;
    @Column(name = "description",length = 20)
    private String description;
    private Boolean available = Boolean.FALSE;
    //@JsonBackReference
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "sys_role_permission",schema = "sys_role_permission"
            ,joinColumns = {@JoinColumn(name = "role_id",columnDefinition = "INT(11)")}
            ,inverseJoinColumns = {@JoinColumn(name = "permission_id",columnDefinition = "INT(11)")})
    private List<SysPermission> permissions;
    //@JsonBackReference
    @ManyToMany
    @JoinTable(name = "sys_user_role",schema = "sys_user_role"
            ,joinColumns = {@JoinColumn(name = "role_id",columnDefinition = "INT(11)")}
            ,inverseJoinColumns = {@JoinColumn(name = "sysuser_id",columnDefinition = "INT(11)")})

    private List<SysUser> userInfos;

    //@JsonBackReference
    public List<SysUser> getUserInfos() {
        return userInfos;
    }
    //@JsonBackReference
    public void setUserInfos(List<SysUser> userInfos) {
        this.userInfos = userInfos;
    }

    public List<SysPermission> getPermissions() {
        return permissions;
    }

    public void setPermissions(List<SysPermission> permissions) {
        this.permissions = permissions;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCnname() {
        return cnname;
    }

    public void setCnname(String cnname) {
        this.cnname = cnname;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Boolean getAvailable() {
        return available;
    }

    public void setAvailable(Boolean available) {
        this.available = available;
    }
}
